﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Gman.Entity.Entities;
using System.Collections.Generic;
using System.Web.Mvc;
using Gman.WebApp.ServiceControllers;
using System.Text;

namespace Gman.WebApp.Models
{
    public class ProveedorModelValidator : ValidationBase
    {

        public List<KeyValuePair<string, string>> Validate(ProveedorModel model)
        {
            PersonalModelValidator validator = new PersonalModelValidator();

            validator.RequiredFieldValidation("proveedor.RucProv", model.proveedor.RucProv, "Ruc");
            validator.RequiredFieldValidation("proveedor.RazonSProv", model.proveedor.RazonSProv, "Razon");
            validator.RequiredFieldValidation("proveedor.DirecProv", model.proveedor.DirecProv, "Direc");
            //validator.RequiredFieldValidation("Ubigeo.CodDpto", model.Ubigeo.CodDpto, "CodDpto");
            //validator.RequiredFieldValidation("Ubigeo.CodProv", model.Ubigeo.CodProv, "CodProv");
            //validator.RequiredFieldValidation("Ubigeo.CodDist", model.Ubigeo.CodDist, "CodDist");
            validator.RequiredFieldValidation("proveedor.NroTelfProvee", model.proveedor.NroTelfProvee, "NroTelfProvee");
            validator.RequiredFieldValidation("proveedor.AnexProv", model.proveedor.AnexProv, "AnexProv");
            validator.RequiredFieldValidation("proveedor.FaxProv", model.proveedor.FaxProv, "FaxProv");
            validator.RequiredFieldValidation("proveedor.NroCeluProvee", model.proveedor.NroCeluProvee, "NroCeluProvee");

            return validator.ValidationList;
        }

        public static string BuildErrorMessage(List<KeyValuePair<string, string>> validationList)
        {
            StringBuilder sb = new StringBuilder(string.Empty);
            if (validationList.Count > 0)
                sb = new StringBuilder("Please fix the following error(s):");
            foreach (var validationError in validationList)
            {
                sb.Append("\n - ").Append(validationError.Value);
            }
            return sb.ToString();
        }
    }
}
